#include "rect.h"
#include "math.h"
#include "math_core.h"
#include "util/mmgr.h"		// Needs to come in early


using namespace math;


Rect::Rect()
{

}

Rect::Rect(const math::Vec2& pos, const math::Vec2& size) :
	Pos(pos),
	Size(size)
{
	
}

Rect::~Rect()
{

}


void Rect::GetRotatedCoords(float Rotation, math::Vec2 CoordA[4])
{
	float				RadRotation = Rotation * DEG_TO_RAD;
	math::Vec2			Width(cosf(RadRotation)*Size.x, cosf(RadRotation + MATH_HALF_PI)*Size.x);
	math::Vec2			Height(sinf(RadRotation)*Size.y, sinf(RadRotation+ MATH_HALF_PI)*Size.y);
	
	CoordA[0].x = Pos.x; 						CoordA[0].y = Pos.y; 
	CoordA[1].x = Pos.x+ Height.x; 				CoordA[1].y = Pos.y + Height.y; 
	CoordA[2].x = Pos.x+ Width.x; 				CoordA[2].y = Pos.y + Width.y; 
	CoordA[3].x = Pos.x+ Width.x + Height.x;	CoordA[3].y = Pos.y + Width.y + Height.y; 
}

void Rect::GetCenteredRotatedCoords(float Rotation, math::Vec2 CoordA[4])
{
	float				RadRotation = Rotation * DEG_TO_RAD;
	math::Vec2			Width(cosf(RadRotation)*Size.x, cosf(RadRotation + MATH_HALF_PI)*Size.x);
	math::Vec2			Height(sinf(RadRotation)*Size.y, sinf(RadRotation+ MATH_HALF_PI)*Size.y);
	
	CoordA[0].x = Pos.x - Width.x - Height.x;	CoordA[0].y = Pos.y - Width.y - Height.y;
	CoordA[1].x = Pos.x - Width.x + Height.x;	CoordA[1].y = Pos.y - Width.y + Height.y;
	CoordA[2].x = Pos.x + Width.x - Height.x;	CoordA[2].y = Pos.y + Width.y - Height.y;
	CoordA[3].x = Pos.x + Width.x + Height.x;	CoordA[3].y = Pos.y + Width.y + Height.y;
}

